/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.AttachmentResponse
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.TaskAttachmentCollectionResource
import java.io.File

/**
 * TaskAttachments
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface TaskAttachmentsApi {


    /**
     * List attachments on a task
     */
    @GetMapping("/runtime/tasks/{taskId}/attachments")
    fun listTaskAttachments(
        @PathVariable("taskId") taskId: String
    ): R<Any>

    /**
     * This endpoint can be used in 2 ways: By passing a JSON Body (AttachmentRequest) to link an external resource or by passing a multipart/form-data Object to attach a file.
    NB: Swagger V2 specification does not support this use case that is why this endpoint might be buggy/incomplete if used with other tools.
     */
    @PostMapping("/runtime/tasks/{taskId}/attachments")
    fun createAttachment(
        @PathVariable("taskId") taskId: String,
        @RequestBody(required = false) body: TaskAttachmentCollectionResource?,
        @RequestParam(name = "file", required = false) file: File?,
        @RequestParam(name = "name", required = false) name: String?,
        @RequestParam(name = "description", required = false) description: String?,
        @RequestParam(name = "type", required = false) type: String?
    ): R<AttachmentResponse>

    /**
     * Get an attachment on a task
     */
    @GetMapping("/runtime/tasks/{taskId}/attachments/{attachmentId}")
    fun getAttachment(
        @PathVariable("taskId") taskId: String,
        @PathVariable("attachmentId") attachmentId: String
    ): R<AttachmentResponse>

    /**
     * Delete an attachment on a task
     */
    @DeleteMapping("/runtime/tasks/{taskId}/attachments/{attachmentId}")
    fun deleteAttachment(
        @PathVariable("taskId") taskId: String,
        @PathVariable("attachmentId") attachmentId: String
    ): R<Any>

    /**
     * The response body contains the binary content. By default, the content-type of the response is set to application/octet-stream unless the attachment type contains a valid Content-type.
     */
    @GetMapping("/runtime/tasks/{taskId}/attachments/{attachmentId}/content")
    fun getAttachmentContent(
        @PathVariable("taskId") taskId: String,
        @PathVariable("attachmentId") attachmentId: String
    ): R<Any>
}